package com.cy.wangly.rest.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class OrdinaryController {
    Logger logger = LoggerFactory.getLogger(OrdinaryController.class);

    @RequestMapping(value = "/getNum", method = RequestMethod.GET)
    public int getRandomInt() {
        Random random = new Random();
        Integer num = random.nextInt(100);
        logger.info("getRandomInt:" + num);
        return num;
    }

    @RequestMapping(value = "/addOne", method = RequestMethod.POST)
    public int addOne(@RequestBody int num) {
        return num + 1;
    }

    @RequestMapping(value = "/addTwo", method = RequestMethod.GET)
    public int addTwo(Integer num) {
        return num + 2;
    }

    @RequestMapping(value = "/getOpposite", method = RequestMethod.POST)
    public boolean getOpposite(@RequestBody boolean b) {
        logger.info("getOpposite:" + b);
        return !b;
    }
}
